package com.fy56.platform.goodsTracking.car.quartz;

import com.fy56.platform.goodsTracking.car.api.CarUpdateApi;
import com.fy56.platform.goodsTracking.car.mode.Ordersynchronize;
import com.fy56.platform.goodsTracking.car.service.OrderSynchronizeService;
import com.fy56.platform.goodsTracking.jdbc.datasource.DBManage;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by XTK on 2017-02-28.
 */
@Service
public class CarUpload {
    @Autowired
    private OrderSynchronizeService orderSynchronizeService;
    static Logger log = Logger.getLogger(CarUpload.class);
    @Autowired
    private DBManage dbManage;
    @Autowired
    private CarUpdateApi updateApi;

    public void upload() {
        //查询本地数据库设置
        //查询所有需要上传的组织代码

        List<Ordersynchronize> orderSynchronizeList = orderSynchronizeService.listOrderSynchronize();
        for (Ordersynchronize orderSynchronize : orderSynchronizeList) {
            log.info("执行无车承运人单据上传操作:Organizationcode:" + orderSynchronize.getOrganizationcode()
                    + ";---开始---");
            try {
                // dbManage.setDBLink(orderSynchronize.getOrganizationcode());//切换数据库
                updateApi.doUpload_Track(orderSynchronize);
                //运单业务类型数据信息
            } catch (Exception e) {
                log.info("执行无车承运人单据上传操作:Organizationcode:" + orderSynchronize.getOrganizationcode()
                        + ";---错误---" + e.getMessage());
            }
        }

        try {
            Thread.sleep(10000);//休息一会
        } catch (InterruptedException ire) {
        }
    }
}
